//
//  HeaderCVCell.m
//  MMLOOK
//
//  Created by dllo on 15/9/16.
//  Copyright (c) 2015年 武俊娥. All rights reserved.
//

#import "HeaderCVCell.h"
#import "UIImageView+WebCache.h"

@interface HeaderCVCell ()

@property(nonatomic, retain) UIImageView *posterImageView;

@end

@implementation HeaderCVCell

- (void)dealloc
{
    [_posterImageView release];
    [_image_url release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self setupImageView];
    }
    return self;
}

- (void)setupImageView
{
    self.posterImageView = [[UIImageView alloc] init];
    _posterImageView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:_posterImageView];
    [_posterImageView release];
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    [super applyLayoutAttributes:layoutAttributes];
    
    _posterImageView.frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height);
}

#pragma mark 重写set方法
- (void)setImage_url:(NSString *)image_url
{
    if (_image_url != image_url) {
        [_image_url release];
        _image_url = [image_url retain];
    }
    
    NSURL *url = [NSURL URLWithString:[_image_url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    [self.posterImageView sd_setImageWithURL:url placeholderImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"home" ofType:@"jpg"]]];//设置图片和占位图片
}

@end
